﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using QL_DTTN.DAL;
namespace QL_DTTN.DTO.DTO
{
    public partial class ChiTietDiemCong
    {
        public DataTable dataTable(string soBaoDanh)
        {
            string sql = " select D.maDiemCong,D.tenDiemCong,D.loai,D.diem from " + _tableName + " C inner join DiemCong D on C.MaDiemCong=D.MaDiemCong where C.SoBaoDanh=@pSoBaoDanh ";
            SqlDataProvider dp = new SqlDataProvider();
            dp.AddParameter(new SqlParameter("@pSoBaoDanh", soBaoDanh));
            return dp.ExDataTable(sql, true);
        }
        public bool them(List<ChiTietDiemCong>lstChiTietDiemCong)
        {
            List<string> lstStr = new List<string>();
            SqlDataProvider dp = new SqlDataProvider();
            for (int i = 0; i < lstChiTietDiemCong.Count(); i++)
            {
                string subStr = " insert into " + _tableName + " (SoBaoDanh,MaDiemCong) values (@pSoBaoDanh"+i+",@pMaDiemCong" + i + ") ";
                dp.AddParameter(new SqlParameter("@pSoBaoDanh" + i, lstChiTietDiemCong[i].SoBaoDanh));
                dp.AddParameter(new SqlParameter("@pMaDiemCong" + i, lstChiTietDiemCong[i].MaDiemCong));
                lstStr.Add(subStr);
            }
            return dp.runSQLListQuery(lstStr, true);
        }
        public double TongDiemCong(string soBaoDanh)
        {
            string sql = " select Sum(isNUll(D.diem,0)) from ThiSinh T left join  " + _tableName + " C on T.SoBaoDanh=C.SoBaoDanh left join DiemCong D on C.MaDiemCong=D.MaDiemCong where T.SoBaoDanh=@pSoBaoDanh ";         
            SqlDataProvider dp = new SqlDataProvider();
            dp.AddParameter(new SqlParameter("@pSoBaoDanh", soBaoDanh));
            object kq = 0;
            dp.RunReturnSQL(sql, ref kq, true);
            return Convert.ToDouble(kq);
        }
    }
}
